package com.hr.cookie;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("cookie")
@ResponseBody
public class CookieController {

//    取cookie的值
//    @param name
//    @return


    @RequestMapping("date")
    public String date(@CookieValue(value = "cookieName") String name){
        System.out.println("name = " + name);
        return name;
    }

    @GetMapping("save")
    public String save(HttpServletResponse response){
        Cookie cookie = new Cookie("name", "root");
        response.addCookie(cookie);
        return "ok";
    }

}
